<script type="text/javascript">

    $(document).ready(function () {
        var pocet = 0;
        $('.login_name').qtip({
            content:{
                url:"<?= base_url();?>profile/getUserStats",
                title:{
                    text:'Profil & moje štatistiky',
                    button:"<a class='close'>X</a>"
                }
            },
            show:{
                effect:function (offset) {
                    $(this).slideDown(300); // "this" refers to the tooltip
                }
            },

            hide:{ when:'inactive', delay:60000, effect:function (offset) {
                $(this).slideUp(300); // "this" refers to the tooltip
            } },
            style:{
                tip:{ // Now an object instead of a string
                    corner:'topLeft', // We declare our corner within the object using the corner sub-option
                    color:'#6fccff',
                    size:{
                        x:8, // Be careful that the x and y values refer to coordinates on screen, not height or width.
                        y:8 // Depending on which corner your tooltip is at, x and y could mean either height or width!
                    }
                }, 'font-size':11, color:'#222222'  } });


    });


</script>

<?php
if ($this->session->userdata("sess_user_id") == null) {
    echo "<a style='color: black;' href='" . base_url() . "login' rel='facebox'>Prihláste sa prosím</a> | ";
    echo "<a style='color: black;' href='" . base_url() . "registration' rel='facebox'><img src='" . base_url() . "css/images/registration.png' style='vertical-align: top;margin-right:2px;border:none;'>Nový účet</a> | ";
    echo "<a style='color: black;' href='" . base_url() . "forgottenPassword' rel='facebox'>Zabudli ste heslo?</a>";
} else {
    ?>
<script type="text/javascript">

    function findLocation() {
        var mygeo = null;
        if (navigator.geolocation) {
            mygeo = navigator.geolocation;
        } else {
            if (google.gears) {
                mygeo = google.gears.factory.create('beta.geolocation');
            }
        }
        if (mygeo !== null) {
            mygeo.getCurrentPosition(successCallback, errorCallback, {maximumAge:3000000});
        }
    }

    function successCallback(position) {

        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;

        // grab the coordinates and set the zoom
        var latlng = new google.maps.LatLng(latitude, longitude);
        var zoom = 15;

        //center this joint
        map.setCenter(latlng, zoom);

        //reverse geocode to get the address
        var geocoder;
        geocoder = new google.maps.Geocoder();
        var infowindow = new google.maps.InfoWindow();
        var mark;

        if (geocoder) {
            geocoder.geocode({'latLng':latlng}, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[1]) {
                        map.setZoom(14);
                        mark = new google.maps.Marker({
                            position:latlng,
                            map:map,
                            icon:'<?= base_url();?>css/images/home_map.png'
                        });
                        infowindow.setContent('Vaša poloha je: <br />' + results[0].formatted_address + '.');
                        infowindow.open(map, mark);
                    } else {
                        alert("Sorry, I could not determine your location");
                    }
                } else {
                    alert("Geocoder failed due to: " + status);
                }
            });
        }

    }

    function errorCallback() {
        document.getElementById("location").innerHTML = "&lt;strong&gt;Sorry, we couldn't find your location.&lt;/strong&gt;";
    }
    function clock() {
        function pad(n) {
            return n < 10 ? '0' + n : n
        }

        /* use a function for the exact format desired... */
        function ISODateString(d) {
            function pad(n) {
                return n < 10 ? '0' + n : n
            }

            return d.getDate() + '.'
                    + pad(d.getMonth() + 1) + '.'
                    + pad(d.getFullYear()) + ' '
                    + pad(d.getHours()) + ':'
                    + pad(d.getMinutes()) + ':'
                    + pad(d.getSeconds());
        }

        cas_ = new Date();

        $('#datetime').text(ISODateString(cas_));
        setTimeout('clock()', 1000);
    }
    // function checkNew() {

    // var id = $('#last_').text();
    //   $.ajax({
    //         type: 'POST',
    //         data: { 'id': id },
    //         url: '<?= base_url();?>reports/checkNewest',
    //         success: function(response){
    //           pocet = response;
    //           if (response==1) $('#news_').html(" | <span style='color:red;font-weight:bold;'>"+response+" nová udalosť!</span>");
    //           else if (response==2 || response==3 || response==4) $('#news_').html(" | <span style='color:red;font-weight:bold;'>"+response+" nové udalosti!</span>");
    //           else if (response>4) $('#news_').html(" | <span style='color:red;font-weight:bold;'>"+response+" nových udalosti!</span>");
    //         }
    //       });


    //    setTimeout('checkNew()',15000);
    // }

    $(document).ready(function () {

        clock();
// checkNew();

// pocet = 3;

// $(this).qtip({
//    content: {
//         url: '<?= base_url();?>reports/getNewestReports/' + pocet ,
//         title: {
//         text: 'Posledné udalosti',
//         button: "<a class='close'>X</a>"
//       }
//     },
//     show: {
//               effect: function (offset) {
//                   $(this).slideDown(100); // "this" refers to the tooltip
//               }
//           },
//    style: {
//        tip: { // Now an object instead of a string
//          corner: 'topLeft', // We declare our corner within the object using the corner sub-option
//          color: '#6fccff',
//          size: {
//             x: 8, // Be careful that the x and y values refer to coordinates on screen, not height or width.
//             y : 8 // Depending on which corner your tooltip is at, x and y could mean either height or width!
//           }
//         },'font-size': 11, color: '#222222'  } });


        $('#locate_me').click(function () {
            findLocation();
            console.log(datum);
            return false;

        });


    });
</script>
<?php

    $href = base_url() . "main/logout";
    echo "<div style='float:left;'><b class='login_name'>" . $this->session->userdata("sess_login") . "</b>
  <span id='last_' style='display:none;'>" . $this->session->userdata('last_report_id') . "</span><span id='news_'></span>
	</div><div style='float:right;'><a href='$href' style='color:black;text-align:right'>Odhlásiť</a> | Aktuálny čas: <span id='datetime'></span>
	</div>";
} ?>

<!-- <span id='locate_me'><img src='".base_url()."css/images/locate.png' style='vertical-align: top;margin-right:2px;border:none;'>Lokalizovať moju polohu</span>  -->